package com.splant.android.smart.SystemDefinedLevel.Menu;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.splant.android.R;

import java.util.List;

/**
 * Created by Administrator on 2016/1/12.
 */
public class MenuAdapter extends BaseAdapter {

    private List<Menu> menuList;
    private LayoutInflater mInflater;
    public MenuAdapter(Context context,List<Menu> menuList)
    {
        this.mInflater = LayoutInflater.from(context);
        this.menuList=menuList;

    }
    @Override
    public int getCount() {
        return menuList.size();
    }

    @Override
    public Object getItem(int i) {
        return menuList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder holder;
        if (view==null)
        {
            view = mInflater.inflate(R.layout.system_menu_adapter_item, null);
            holder = new ViewHolder();

            holder.menuIcon=(ImageView)view.findViewById(R.id.menuIconImg);
            holder.menuName=(TextView)view.findViewById(R.id.menuNameTxt);

            view.setTag(holder);
        }
        else
          holder=(ViewHolder)view.getTag();

        holder.menuIcon.setImageResource(menuList.get(i).menuIcon);
        holder.menuName.setText(menuList.get(i).menuName);

        return view;
    }

    public final class ViewHolder
    {
        public ImageView menuIcon;
        public TextView menuName;
    }
}
